#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import Any
from starlette.background import BackgroundTask


class BaseExceptionMixin(Exception):
    code: int
    status_code = 200

    def __init__(self, msg: str = None, data: Any = None, background: BackgroundTask | None = None):
        self.msg = msg
        self.data = data
        # The original background task: https://www.starlette.io/background/
        self.background = background


class RequestError(BaseExceptionMixin):
    code = -1

    def __init__(self, *, msg: str = 'Bad Request', data: Any = None, background: BackgroundTask | None = None):
        super().__init__(msg=msg, data=data, background=background)


class ErrorException(BaseExceptionMixin):
    code = -1

    def __init__(self, msg: str = 'Fail', data: Any = None, background: BackgroundTask | None = None):
        super().__init__(msg=msg, data=data, background=background)


class ValidateError(BaseExceptionMixin):
    code = -1

    def __init__(self, msg: str = 'Bad Request', data: Any = None, background: BackgroundTask | None = None):
        super().__init__(msg=msg, data=data, background=background)


class ForbiddenError(BaseExceptionMixin):
    code = -1

    def __init__(self, msg: str = 'Forbidden', data: Any = None, background: BackgroundTask | None = None):
        super().__init__(msg=msg, data=data, background=background)


class NotFoundError(BaseExceptionMixin):
    code = -1

    def __init__(self, msg: str = 'Not Found', data: Any = None, background: BackgroundTask | None = None):
        super().__init__(msg=msg, data=data, background=background)


class ServerError(BaseExceptionMixin):
    code = -1

    def __init__(
        self, msg: str = 'Internal Server Error', data: Any = None, background: BackgroundTask | None = None
    ):
        super().__init__(msg=msg, data=data, background=background)


class GatewayError(BaseExceptionMixin):
    code = -1

    def __init__(self, msg: str = 'Bad Gateway', data: Any = None, background: BackgroundTask | None = None):
        super().__init__(msg=msg, data=data, background=background)


class AuthorizationError(BaseExceptionMixin):
    code = 403

    def __init__(self, msg: str = 'Permission denied', data: Any = None, background: BackgroundTask | None = None):
        super().__init__(msg=msg, data=data, background=background)


class TokenError(BaseExceptionMixin):
    code = 400

    def __init__(self, msg: str = 'Token is Error', data: Any = None,
                 background: BackgroundTask | None = None):
        super().__init__(msg=msg, data=data, background=background)


class TokenExpired(ErrorException):
    """
    token过期
    """
    code = 401

    def __init__(self, msg: str = 'Token is Expired', data: Any = None,
                 background: BackgroundTask | None = None):
        super().__init__(msg=msg, data=data, background=background)